//
//  WJCustomCodeCollectionViewController.m
//  JerryIos
//
//  Created by 王军 on 2018/2/2.
//  Copyright © 2018年 王军. All rights reserved.
//

#import "WJCodeCollectionController.h"
#import "WJCodeCollectionCell.h"
#import "WJCar.h"

@interface WJCodeCollectionController ()

@property (nonatomic, strong) NSArray *carArray;

@end

@implementation WJCodeCollectionController

static NSString * const reuseIdentifier = @"carCollectionCell";

- (NSArray *)carArray {
    if (_carArray == nil) {
        WJCar *car1 = [[WJCar alloc] init];
        car1.icon = @"icon_home";
        car1.name = @"aaa";
        
        WJCar *car2 = [[WJCar alloc] init];
        car2.icon = @"icon_home";
        car2.name = @"bbb";
        
        WJCar *car3 = [[WJCar alloc] init];
        car3.icon = @"icon_home";
        car3.name = @"ccc";
        
        WJCar *car4 = [[WJCar alloc] init];
        car4.icon = @"icon_home";
        car4.name = @"ddd";
        
        WJCar *car5 = [[WJCar alloc] init];
        car5.icon = @"icon_home";
        car5.name = @"eee";
        
        NSMutableArray *mutArray = [NSMutableArray array];
        [mutArray addObject:car1];
        [mutArray addObject:car2];
        [mutArray addObject:car3];
        [mutArray addObject:car4];
        [mutArray addObject:car5];
        
        _carArray = mutArray;
    }
    return _carArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
     self.collectionView.backgroundColor = [UIColor whiteColor];
    
    // Register cell classes
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
}

#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.carArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    WJCodeCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    cell.car = self.carArray[indexPath.row];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    WJCar *car = self.carArray[indexPath.row];
    NSLog(@"===%@",car.name);
}

@end
